package com.yzt.minemodule.vm;

import android.app.Application;

import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;

import com.yzt.zhuju.network.AresSubscriber;
import com.yzt.zhuju.network.biz.BizLayer;
import com.yzt.zhuju.network.entity.mine.wallet.OrderBaseBean;
import com.yzt.zhuju.network.entity.mine.wallet.OrderListBean;
import com.yzt.zhuju.network.entity.mine.wallet.WalletBaseBean;
import com.yzt.zhuju.network.entity.mine.wallet.WalletBean;
import com.rxjava.rxlife.ScopeViewModel;

import java.util.List;

/**
 * 作者：bobwang
 * 创建时间：2023-11-17 10:00:52
 * 描述：
 */
public class OrderViewModel extends ScopeViewModel {

    /**
     * 获取列表成功
     */
    public MutableLiveData<List<WalletBean>> friendListSuccessEvent = new MutableLiveData<>();

    /**
     * 获取列表成功
     */
    public MutableLiveData<Boolean> friendListFinallyEndEvent = new MutableLiveData<>();

    /**
     * 获取列表成功
     */
    public MutableLiveData<List<OrderListBean>> OrderListSuccessEvent = new MutableLiveData<>();

    /**
     * 获取列表成功
     */
    public MutableLiveData<Boolean> OrderListFinallyEndEvent = new MutableLiveData<>();

    public OrderViewModel(@NonNull Application application) {
        super(application);
    }

    /**
     * 获取钱包列表
     */
    public void getWalletList(int extraId, int currentPage, int pageSize) {
        BizLayer.getInstance().getMineModule().walletList(extraId, currentPage, pageSize, new AresSubscriber<WalletBaseBean>() {
            @Override
            protected void onSuccess(WalletBaseBean list) {
                if (extraId == 3) {
                    friendListSuccessEvent.postValue(list.getTransactionsList());
                } else {
                    friendListSuccessEvent.postValue(list.getList());
                }
            }

            @Override
            protected void onFinallyEnd() {
                super.onFinallyEnd();
                friendListFinallyEndEvent.postValue(true);
            }
        });
    }

    /**
     * 获取订单列表
     */
    public void getOrder(int extraId, int currentPage, int pageSize) {
        BizLayer.getInstance().getMineModule().orderList(extraId, currentPage, pageSize, new AresSubscriber<OrderBaseBean>() {
            @Override
            protected void onSuccess(OrderBaseBean list) {
                OrderListSuccessEvent.postValue(list.getOrderList());
            }

            @Override
            protected void onFinallyEnd() {
                super.onFinallyEnd();
                friendListFinallyEndEvent.postValue(true);
            }
        });
    }
}
